<?php
class MagicAction extends CommonAction {
	function index(){
        parent::_list();
		$this->display();
	}
	
	public function insert(){
		$id=$this->_post('id');
		$praisefeild=$this->_post('praisefeild');
		$praisename=$this->_post('praisename');
		$min=$this->_post('min');
		$max=$this->_post('max');
		$praisecontent=$this->_post('praisecontent');
		$praisenumber=$this->_post('praisenumber');
		$chance=$this->_post('chance');
		$data = array();
		foreach($id as $k=>$v){
			$data[$k]['id'] = $id[$k];
			$data[$k]['praisefeild'] =$praisefeild[$k];
			$data[$k]['praisename'] = $praisename[$k];
			$data[$k]['min'] = $min[$k];
			$data[$k]['max'] = $max[$k];
			$data[$k]['praisecontent'] = $praisecontent[$k];
			$data[$k]['praisenumber'] = $praisenumber[$k];
			$data[$k]['chance'] = $chance[$k];
		}
		$_POST['config'] = serialize($data);
		$_POST['site_id'] = $this->siteid;
		parent::insert();
	}
	public function update(){
		$id=$this->_post('mid');
		$praisefeild=$this->_post('praisefeild');
		$praisename=$this->_post('praisename');
		$min=$this->_post('min');
		$max=$this->_post('max');
		$praisecontent=$this->_post('praisecontent');
		$praisenumber=$this->_post('praisenumber');
		$chance=$this->_post('chance');
		$data = array();
		foreach($id as $k=>$v){
			$data[$k]['id'] = $id[$k];
			$data[$k]['praisefeild'] =$praisefeild[$k];
			$data[$k]['praisename'] = $praisename[$k];
			$data[$k]['min'] = $min[$k];
			$data[$k]['max'] = $max[$k];
			$data[$k]['praisecontent'] = $praisecontent[$k];
			$data[$k]['praisenumber'] = $praisenumber[$k];
			$data[$k]['chance'] = $chance[$k];
		}
		$_POST['config'] = serialize($data);
		parent::update();
	}
	public function edit(){
		$id = $this->_get('id');
		$info = $this->dao->where(array('id' => $id))->find();
		$info['config'] = unserialize($info['config']);
		$this->assign('info',$info);
		$this->display();
	}
	
	//显示添加活动对象窗口
	public function addMember(){
		$this->listmap="1";
		$this->id=$this->_get('id');
		$this->listmap.=" and m.site_id=".$this->siteid;
		//改变当前数据模型对象，查询用户表
		$this->dao = M('Member');
        parent::_list("m","left join __MEMBER_GROUP__ as g on m.group_id=g.id","m.*,g.title as groupname");
		$this->display('Public:addMember');
	}
}

?>